#include "rcstat.h"
#include "zuc/nml_intf/zuc_nml.hh"

#include "config.h"
#include "log/zlog.hh"
#include "jkutil/iniparser.h"

using task::RcStat;

#define RCSTAT_INFO(fmt, ...) zlog()->info("[RCSTAT] " fmt, ##__VA_ARGS__)
#define RCSTAT_ERR(fmt, ...) zlog()->error("[RCSTAT] " fmt, ##__VA_ARGS__)

RcStat* RcStat::get()
{
    static RcStat* instance = nullptr;
    if (instance == nullptr)
    {
        instance = new RcStat();
    }
    return instance;
}
RcStat::RcStat() { stat = zucStatus; }
int RcStat::init()
{
    load_cfg(ZUC_USER_SETTINGS_FILE);
    return 0;
}

int RcStat::load_cfg(std::string cfgfile)
{
    auto parser = std::make_shared<Util::IniParser>(cfgfile.c_str());

    std::string rcname;
    parser->get("ROBOT.NAME", rcname, "JKROBOT");
    strncpy(stat->robotName, rcname.c_str(), sizeof(stat->robotName));
    parser->get("ZUC.DEBUG", stat->debug, 0);

    return 0;
}